from game import zz_game
from zz import zz_log, zz_img

log = zz_log.of()


class Game(zz_game.ZZ_Game):
    def __init__(self, d, has_prize=True):
        super().__init__(d, has_prize)

    def get_name(self):
        return "修道"

    def game_alert(self):
        self.alert_close_by_file('./game/img/修道')

    def play_alert(self):
        if not self.img_exit('./game/img/修道/play02.png', 3):
            return
        # self.d.sleep(1)
        self.log_msg("存在弹窗，进行关闭")
        if self.img_exit('./game/img/修道/play01.png', 2):
            self.log_msg(f"战力下降")
            self.img_click('./game/img/修道/play_buy.png')
        else:
            self.log_msg(f"战力上升")
            self.img_click('./game/img/修道/play_get.png')

        if self.img_exit('./game/img/修道/play_confirm.png', 1):
            self.log_msg(f"存在确认弹窗，进行确定")
            self.img_click('./game/img/修道/play_confirm.png')

    def play_prize(self):
        # 秘境扫荡
        self.log_msg(f"点击秘境")
        self.img_click('./game/img/修道/play_prize.png', 5)
        if not self.img_exit('./game/img/修道/play_prize01.png', 3):
            self.log_msg(f"等级太低，秘境")
            return
        self.img_click_if_exists('点击邪修讨伐', './game/img/修道/play_prize01.png', './game/img/修道/play_prize02.png')
        self.img_click_if_exists('点击扫荡', './game/img/修道/play_prize02.png', './game/img/修道/play_prize03.png')
        self.log_msg(f"点击扫荡")
        self.d.click(600, 1380)
        # if self.img_click('./game/img/修道/play_prize03.png', 3):
        #     self.click_bottom()
        self.d.sleep(1)
        self.click_bottom()
        self.click_bottom()
        self.click_bottom()
        self.click_bottom()
        self.log_msg(f"秘境扫荡-完成")

    def handle_main(self):
        self.game_alert()
        self.log_msg("等待进入游戏")
        self.img_click_for('点击开始游戏', './game/img/修道/start.png')
        self.log_msg("等待进入游戏主界面")
        self.img_exit('./game/img/修道/game_main.png', 100)
        self.log_msg("已进入游戏主界面")

        self.game_alert()
        self.play_prize()

        self.log_msg("开始开鼎")
        while not self.check_done():
            self.play_alert()
            for i in range(10):
                self.log_msg(f"点击鼎-{i}")
                self.img_click('./game/img/修道/play.png', 5, 2)
                self.play_alert()
            self.game_alert()

        return True
